var UserWork_qryPager ;
(function(scope) {
	var CUserWorkSet = PageTpl.extend({
		constructor : function(param) {
			this.version = "1.0";
			this.param =param || {};
			this.action_type="";
		},	
		render_info : function(reply) {
			var tbodyJq = $("#"+"UserWork_list");
			tbodyJq.empty();
            var list = reply.list;
  			if(list.length >0){
  			  for(var i=0;i<list.length;i++)
	  			{
  				    var map = list[i];
	  				var className = i%2 ==0?"":"gray";
	  				var trJq =$('<tr class='+className+' style="cursor:hand;"> <td> <input type="radio" name="acct_radio" /></td>'+
                                                                                            '<td>'+map['uid']+'</td>'+
                                                                                            '<td>'+map['company']+'</td>'+
                                                                                            '<td>'+map['province']+'</td>'+
                                                                                            '<td>'+map['city']+'</td>'+
                                                                                            '<td>'+map['beg_work_year']+'</td>'+
                                                                                            '<td>'+map['end_work_year']+'</td>'+
                                                                                            '<td>'+map['summary']+'</td>'+
                                            		  				'</tr>').bind("click",function(){
	  					if (UserWork_form.action_type =='A' || UserWork_form.action_type =='M'){
	  						if(confirm("是否取消当前操作？")){
	  							$('#cancel_UserWork_btn').trigger("click");
	  						 }else{
	  							 return ; 
	  						 }
	  					}
	  					$(this).find(":radio").attr("checked",true);
	  					var map = $(this).data("UserWork_data");
	  					UserWork_form.set_record(map);

	  				}).data("UserWork_data",map);
	  				tbodyJq.append(trJq);
	  			}
  			  	tbodyJq.find("tr:eq(0)").trigger("click");
  			        UserWorkSet.setDisabled("0");
  				
  			}
		},
		queryUserWorkList : function(param) {
			var param=param||{};
			//page_index 起始页 page_size 每页的记录行数
			param['page_size']=1;
			if (!UserWork_qryPager) {
				var pager = new Pager('pageNav','ICustHander','queryUserWorkList', false, [param],
						this.render_info, false, false, false, null, 'simple', false);
				window.UserWork_qryPager = pager;
			} else {
				Service.asExcute('ICustHander','queryUserWorkList' , [param], this.render_info);
			}
		}
	})
	window.UserWorkSet = new CUserWorkSet();
}(window));

(function(scope) {
	var CUserWork_form = FormTpl.extend({
		constructor : function() {
			this.base({'form_id':'UserWork_form_id','service_name':'ICustHander','method':''});
		},
		set_record:function(data){ //点击列表记录，将列表值设置到表单上,列表记录绑定方法
			var data  = data || {};
			this.record_click(data);
		},
		mod_record:function(param){ //点击修改按钮，调用方法，修改按钮绑定方法
			//var param =param||{'method':'updateUser'};
			this.param.method='updateUserWork';
			this.mod(param);
		},
		add_record:function(){ //点击新增按钮调用方法,新增按钮绑定方法
			this.add();
		},
		del_record:function(){ // 点击删除按钮，调用方法,删除按钮绑定方法
			this.param.method='deleteUserWork';
			this.del();
			
		},
		/**
		 * @param  reply后台返回结果
		 */
		after_del:function(reply){ 
		 //必须实现，删除后调用的方法
			if(reply == null || reply =='' || reply.result=='' || reply.result==true ){
	           pop({"text":"操作成功！"});
	        }else{
	           pop({"text":reply.result}); 
	        }
			UserWork_form.param.method='';
			UserWork_form.param.action_type='';
			UserWorkSet.queryUserWorkList();
		},
		/**
		 * @param  reply后台返回结果
		 */
		after_save:function(reply){ 
		 //必须实现，新增保存，修改保存后调用的方法
		    if(reply == null || reply =='' || reply.result=='' || reply.result==true  ){
		       pop({"text":"操作成功！"});
		    }else{
		       pop({"text":reply.result}); 
		    }
			UserWork_form.param.method='';
			UserWork_form.param.action_type='';
			UserWorkSet.queryUserWorkList();
		},
		query:function(data){
			var data  = data || {};
			Service.asExcute('ICustHander','getUserWorkByCond' , [data], function (replay){				
				UserWork_form.set_record(replay);
			});
		}
	})
	window.UserWork_form = new CUserWork_form();
}(window));


$(function() {
	UserWorkSet.setDisabled("0");
	UserWorkSet.queryUserWorkList();
	addEventById("insert_UserWork_btn",null,"click",function(){
		UserWork_form.add_record();
	});
	addEventById("update_UserWork_btn",null,"click",function(){
		UserWork_form.mod_record();
	});
	addEventById("delete_UserWork_btn",null,"click",function(){
	    UserWork_form.del_record();
	});
	addEventById("cancel_UserWork_btn",null,"click",function(){
		UserWorkSet.action_type ="";
		UserWorkSet.setDisabled("0");
	});
	addEventById("save_UserWork_btn",null,"click",function(){
		if(UserWork_form.param.action_type=='A'){
			UserWork_form.param.method='insertUserWork';
		}else if(UserWork_form.param.action_type=='M'){
			UserWork_form.param.method='updateUserWork';
		}
		UserWork_form.save();
	});
	//UserWork_form.query({uid:uid});
	downLoadSelectDatas();
	
})